var bump_direction;
actor_control();
character_hp[0] = min(character_hp[0], character_hp[1]);
actor_hp[0] = min(character_hp[0], character_hp[1]);
actor_hp[1] = character_hp[1];
character_dead = ((actor_hp[0] <= 0) or (((y < -sprite_height) or (y > room_height + sprite_height)) and (character_warping == false)));
character_onscreen = ((x > view_xview - 16) and (x < view_xview+view_wview + 16) and (y > view_yview - 16) and (y < view_yview+view_hview + 16));
character_onground = place_meeting(x,y + actor_g,obj_solid);
character_talking_to = collision_line(x,y+16,x+(24 * image_xscale),y+16,obj_character,true,true);
if (character_dead == false)
{
    if ((character_onscreen == false) && (alarm[2] != -1))
    {
        alarm[2] = ((room_speed * 2.5) - (room_speed / 2));
    }
    if (character_bumped == 0)
    {
        character_bumpedid = (instance_place(x,y,obj_character));
        if (character_bumpedid > 0)
        {
            if ((character_bumpedid.object_index != object_index) and (((instance_place(x,y,obj_character)).character_dead == false)) and (character_bumpedid.character_canbebumped != character_canbebumped))
            {
                character_bumped = 1;
                exit;
            }
        }
        if (character_item_counter > 0)
        {
            character_item_counter = max(0, character_item_counter - (30 / room_speed));
        }
        else
        {
            if ((character_use_item == true) && (character_item_counter == 0))
            {
                inventory_item_use(character_item_equipped);
            }
            if ((character_use_item == false) && (character_item_counter < 0))
            {
                character_item_counter = 0;
            }
        }
        if (actor_onwater == false)
        {
            if ((character_onground == true) or (actor_onfakeground == true) or (character_climb == true))
            {
                if (character_jump == true)
                {
                    if (character_havejumped <= -2)
                    {
                        character_vsp = (-(actor_g) * (sqrt((2*((character_jumpsp)+abs(character_hsp*4)) / 1))));
                        character_havejumped = 1;
                        character_climb = false;
                    }
                }
                else
                {
                    character_havejumped = -2;
                }
            }
            else
            {
                if (character_havejumped == 0)
                {
                    character_vsp = actor_vsp / 2;
                    character_havejumped = -1;
                }
                if ((character_jump == false) && (character_havejumped == 1) && (sign(actor_vsp) != sign(actor_g)) && (actor_vsp != 0))
                {
                    character_havejumped = 0;
                }
            }
            if (character_walk == true)
            {
                character_hsp = (min(abs(character_hsp) + (30 / room_speed),(character_walksp + (character_sprintsp * character_sprint))) * character_direction);
                character_havewalked = true;
            }
            else
            {
                character_hsp = max(abs(character_hsp) - (30 / room_speed),0) * character_direction;
                if ((character_hsp == 0) && (character_havewalked == true))
                {
                    character_havewalked = false;
                }
            }
        }
        else
        {
            if ((character_jump == true) && (actor_vsp >= 0))
            {
                character_vsp = (-(actor_g) * (sqrt((2*(character_jumpsp+abs(character_hsp*4)) / 1))));
            }
            if ((character_walk == true) && (place_meeting(x + character_direction,y,obj_solid) == false))
            {
                character_hsp = (min(abs(character_hsp) + 0.5,(character_walksp + (character_sprintsp * character_sprint)) / 2) * character_direction);
                character_havewalked = true;
            }
            else
            {
                character_hsp = max(abs(character_hsp) - 0.5,0) * character_direction;
                if (character_hsp == 0) && (character_havewalked == true)
                {
                    character_havewalked = false;
                    actor_hsp = 0;
                }
            }
            actor_vsp /= 2;
        }
        if (character_attack == true)
        {
            character_do_attack();
        }
        if ((place_meeting(x,y,obj_ladder) == true) or (place_meeting(x,((y div 16) + actor_g) * 16,obj_ladder) == true))
        {
            if (character_climb == true)
            {
                var character_ladder;
                if (place_meeting(x,y,obj_ladder) == true)
                {
                    character_ladder = instance_place(x,y,obj_ladder);
                }
                else
                {
                    character_ladder = instance_place(x,((y div 16) + actor_g) * 16,obj_ladder);
                }
                if ((character_onground == true) && (character_climbdir == 1))
                {
                    character_climb = false;
                    character_climbdir = 0;
                }
                x = character_ladder.x + 8;
                actor_hsp = 0;
                actor_vsp = character_climbdir;
                character_havejumped = -2;
            }
        }
        else
        {
            character_climb = false;
            character_climbdir = 0;
        }
        actor_onfakeground = (place_meeting(x,((y div 16) + actor_g) * 16,obj_ladder) == true) and (place_meeting(x,y,obj_ladder) == false);
    }
    else
    {
        if (character_bumped == 1)
        {
            if (instance_exists(character_bumpedid) == true)
            {
                if (sign(x - (character_bumpedid).x) == 0)
                {
                    bump_direction = character_direction;
                }
                else
                {
                    bump_direction = sign(x - (character_bumpedid).x);
                }
                actor_vsp = -4 * actor_g;
                character_hsp = max(character_hsp,character_walksp) * bump_direction;
            }
            character_bumped = 2;
        }
        else
        {
            if (character_onground == true)
            {
                character_hsp = 0;
                character_bumped = 0;
            }
        }
    }
    if (character_vsp != actor_vsp) && (character_vsp != 0)
    {
        actor_vsp = character_vsp;
        actor_vsp_impulse = character_vsp;
        character_vsp = 0;
    }
    if (character_hsp != actor_hsp) and (character_hsp != 0)
    {
        actor_hsp_impulse = ((character_walksp + (character_sprintsp * character_sprint)) * character_direction) * character_walk;
        actor_hsp = character_hsp;
    }
    character_team_control();
}
else
{
    actor_free = false;
    actor_vsp = 0;
    actor_hsp = 0;
    character_hsp = 0;
    character_vsp = 0;
    chracter_jump = false;
    character_walk = false;
    character_climb = false;
    character_sprint = false;
    character_havewalked = false;
    character_bumped = false;
    character_talk = false;
    character_crouch = false;
    if (alarm[0] == -1)
    {
        alarm[0] = room_speed;
        alarm[1] = room_speed / 2;
    }
}
if (global.cutscene == true)
{
    if ((place_meeting(x,y+actor_g,obj_solid) == true) && (character_jump == true))
    {
        character_jump = false;
    }
}
if (place_meeting(x,y,obj_solid) == true)
{
    character_stuck = instance_place(x,y,obj_solid);
}
if (character_stuck > 0)
{
    move_contact_all(point_direction(character_stuck.x,character_stuck.y,character_stuck.xprevious,character_stuck.yprevious),4);
    character_stuck = false;
}
character_sprite_set();
